import request from "@/utils/request";
import { 
  searchRequirementsBugsFrom, 
  Common,
  BugList,
  postRequirementsBugsData,
  getRequirementsBugsDataList,
  CommonRequirementBugs,
  addBugFrom,
  updateBugLevelForm,
  updateBugRoleForm,
  addCommentBugForm,
  updateBugStatusForm,
  getBugStatusListData,
} from "./type";
 
//* BUG管理
// BUG管理相关接口
enum Demands {
    PostRequirementsBugs = "/item/getRequirementsBugs", //获取符合需求的BUG
    GetRequirementsBugs = "/item/getRequirementsBugs/",//根据需求id获取该需求下所有BugList
    AddRequirementBug = "/bug/addRequirementBug",//根据需求添加bug
    FindBugMsgById = "/bug/findBugMsgById",//根据id获取bug详情
    AddBugMsgById = "/bug/addBugMsgById",//根据bugid给bug添加详情
    // GetRoleUser = "/user/getRoleUser",//获取所有的修复人员
    GetBugUsers = "/bug/findBugUsersById/",//根据bugID获取关联修复人
    UpdateBugLevel = "/bug/updateBugLevelById",//根据bugID修改bugLevel
    UpdateBugRole = "/bug/updateBugEditById",//根据bugID修改bugRoles
    UpdateBugStatus = "/bug/updateBugStatusById",//根据bugID修改bugStatus
    GetBugStatusList = "/bug/getBugStatusList",//获取bug状态列表bugStatusList
  }
  
  //! 获取符合需求的bug
  export const postRequirementsBugs = (data: searchRequirementsBugsFrom) =>
    request.post<Common<postRequirementsBugsData<BugList[]>>>(Demands.PostRequirementsBugs, data);

  // 根据需求id获取该需求下所有BugList
  export const getRequirementBugs = (id: number) => 
    request.get<Common<getRequirementsBugsDataList[]>>(`${Demands.GetRequirementsBugs}${id}`);
  
  // 添加一个bug
  export const addRequirementBug = (data: addBugFrom) =>
    request.post<Common<any>>(Demands.AddRequirementBug, data);
  
  // 根据id获取bug详情
  export const findBugMsgById = (id: number) =>
    request.get<Common<CommonRequirementBugs>>(`${Demands.FindBugMsgById}/${id}`);
  
  // 根据bugid给bug添加详情
  export const addBugMsgById = (data: addCommentBugForm) =>
    request.post<Common<any>>(Demands.AddBugMsgById, data);

  // 获取所有的修复人
  // export const getRoleUser = () => request.get(`${Demands.GetRoleUser}?authId=`);

  // 根据bugID获取关联修复人
  export const getBugUsers = (id: number) => request.get(`${Demands.GetBugUsers}${id}`);

  // 根据bugID修改bugLevel
  export const updateBugLevelById = (data: updateBugLevelForm) => request.put(Demands.UpdateBugLevel, data);

  // 根据bugID修改bugRoles
  export const updateBugRoleById = (data: updateBugRoleForm) => request.put(Demands.UpdateBugRole, data);

  // 根据bugID修改bugStatus
  export const updateBugStatusId = (data: updateBugStatusForm) => request.put(Demands.UpdateBugStatus, data);

  //获取bug状态列表bugStatusList
  export const getBugStatusList = () => request.get<Common<getBugStatusListData[]>>(Demands.GetBugStatusList);